package com.ywu.bpmn.standard.api;

import com.ywu.boot.context.YwuContext;
import com.ywu.boot.context.YwuContextHolder;
import com.ywu.bpmn.spi.dto.YwuBpmnDto;
import com.ywu.bpmn.standard.service.YwuActivitiService;
import com.ywu.common.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName YwuActivitiApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2025/4/23 1:56
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/bpmn/activiti")
public class YwuActivitiApi {

    @Autowired
    private YwuActivitiService service;

    /**
    * @Author GroundDemo
    * @Description 部署流程
    * @Date 11:15 2025/4/23
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/deployment")
    public CommonResult<Object> deployFlow(@RequestBody YwuBpmnDto dto) {
        return service.deployFlow(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 发起流程
    * @Date 11:10 2025/4/23
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/start")
    public CommonResult<Object> start(@RequestBody YwuBpmnDto dto) {
        YwuContext currentContext = YwuContextHolder.getCurrentContext();
        service.start(dto, currentContext);
        return CommonResult.success(null);
    }

    /**
    * @Author GroundDemo
    * @Description 查询用户代办列表
    * @Date 10:42 2025/4/23
    * @Param [name]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/toDoList")
    public CommonResult<Object> toDoList(@RequestBody YwuBpmnDto dto) {
        return service.toDoList(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 用户审批
    * @Date 10:42 2025/4/23
    * @Param [taskId]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/complete")
    public CommonResult<Object> complete(@RequestBody YwuBpmnDto dto) {
        YwuContext currentContext = YwuContextHolder.getCurrentContext();
        service.complete(dto, currentContext);
        return CommonResult.success(null);
    }

    /**
    * @Author GroundDemo
    * @Description 查询流程变量
    * @Date 10:42 2025/4/23
    * @Param [taskId]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/queryAllVariables")
    public CommonResult<Object> queryAllVariables(@RequestBody YwuBpmnDto dto) {
        return service.queryAllVariables(dto);
    }
}
